var arrestGrid;
var popup;
var mapObj;
function addSearchResultGrid(){

	  var Arrest = Ext.data.Record.create([
	                                    	
	                                        {
	                                            name: 'id',
	                                            type: 'number'
	                                        }, {
	                                            name: 'drugcode',
	                                            type: 'string'
	                                        }, {
	                                            name: 'admin_en',
	                                            type: 'string'
	                                        }, {
	                                            name: 'admin_ar',
	                                            type: 'string'
	                                        },{
	                                            name: 'noofarrest',
	                                            type: 'number'
	                                        },{name:'noofcases',
	                                        type: 'number'},
	                                        {name:'year_ar',
		                                        type: 'string'
											
											},{
	                                            name: 'quantity',
	                                            type: 'double'
	                                        },{
	                                            name: 'lat',
	                                            type: 'double'
	                                        },{
	                                            name: 'lon',
	                                            type: 'double'
	                                        },{
	                                            name: 'type',
	                                            type: 'number'
	                                        },{
	                                            name: 'regioncode',
	                                            type: 'number'
	                                        }, {
	                                            name: 'drugname',
	                                            type: 'string'
	                                        }
	                                       
	                                        
	                                        ]);
	  
	  var proxy = new Ext.data.HttpProxy({
		  api: {
	        read : 'getArrest.html'
	        	
	    }
	});
	    
	    var reader = new Ext.data.JsonReader({
	        totalProperty: 'total',
	        successProperty: 'success',
	        idProperty: 'row',
	        root: 'arrestModel',
	        messageProperty: 'message'  // <-- New "messageProperty" meta-data
	    }, 
	    Arrest);

	 // The new DataWriter component.
	    var writer = new Ext.data.JsonWriter({
	        encode: true,
	        writeAllFields: false
	    });
	 
	    var arrestStore = new Ext.data.Store({
	        id: 'arrestStore',
	        proxy: proxy,
	        reader: reader,
	        writer: writer,  // <-- plug a DataWriter into the store just as you would a Reader
	      autoSave: true // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
	    });
	   // arrestStore.load({params:{start:0, limit:5}});
	    
	  

				 arrestGrid = new Ext.grid.GridPanel({
					
					
						hide : true,					
						title : 'Arrest Details',
						id : 'arrestGridPan',
						margin:'0 0 0 0',
			store : arrestStore,
							sm : new Ext.grid.RowSelectionModel( {
			singleSelect : true,
			listeners : {
				rowselect : {
					fn : function(sm, index, record) {
						displayDetailLocation(index,record);

					}
				}
			}
		}),		
					
			columns : [{
						id : 'id',
						header : 'UserId',
						hidden:true,
						sortable : true,
						dataIndex : 'id'
					}, 
						
					{
						id : 'drugcode',
						header : drugTitle,
						
						sortable : true,
						dataIndex : 'drugname'
					}
					,
						{
						id : 'type',
						header : 'Type',
						hidden:true,
						sortable : true,
						dataIndex : 'type'
					},
					
					
					{
						id :'admin_en',
							width:80,
						header : cityLabel,
						
						sortable : true,
						dataIndex : 'admin_en'
						
					}, {
						id :'noofarrest',
						header : arrestTitle,
						width:80,
						sortable : false,
						dataIndex : 'noofarrest'
						
					},
					{
						id :'noofcases',
						header : caseTitle,
							width:80,
						
						sortable : true,
						dataIndex : 'noofcases'
							

					},{
						id :'quantity',
						header : quantityTitle,
						width:80,
						sortable : true,
						dataIndex : 'quantity'
           },{
						id :'year_ar',
						header : periodTitle,
						width:80,
						sortable : true,
						dataIndex : 'year_ar'
           },{
						id :'lat',
						header : drugTitle,
						width:80,
						sortable : true,
							hidden:true,
						dataIndex : 'lat'
           },{
						id :'lon',
						header : periodTitle,
						width:80,
						sortable : true,
							hidden:true,
						dataIndex : 'lon'
           },{
						id :'regioncode',
						header : 'regioncode',
						width:80,
							hidden:true,
						sortable : true,
						dataIndex : 'regioncode'
           }
			    
					
					
					
					],
		

		
        title: searchResultTitle,
        height: 150,
        width:300,
		frame:true
       
        });



}
function displayDetailLocation(index,record) {
	// debugger;
	
	/*if (popup != null && popup != '') {
	mapObj.removePopup(popup);
		popup.destroy();
		popup = '';
	}
	
	var lonLat = new OpenLayers.LonLat(record.data.lat, record.data.lon);
	var html = "<div class='popupHead' align='center'><b>" + record.data.city
			+ "<li> Period"+record.data.period+record.data.month+"</li></b>"+
		"<li> no:of cases"+record.data.numberArrest+"</li></div>";

	popup = new OpenLayers.Popup.FramedCloud("", lonLat, new OpenLayers.Size(
		100, 100), html, null, true, closePopup2());
	
	mapObj.addPopup(popup);
	
	mapObj.panTo(lonLat);*/
	
	
	poi( record.data.lat,record.data.lon,record);
	
	//var lon = 46.693631563;var lat = 24.670074585;
	//poi(lon, lat);
}

